package com.itheima.jobs;

import cn.hutool.core.collection.CollectionUtil;
import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

@Component
public class ClearImages {
    @Autowired
    JedisPool jedisPool;

    public void clear() {
        Set<String> needDeleteDatas = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (CollectionUtil.isNotEmpty(needDeleteDatas)) {
            for (String fileName : needDeleteDatas) {
                QiNiuUtil.delete(fileName);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, fileName);
            }
        }
    }
}
